package com.wangyang.stock.business.services;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.wangyang.stock.business.IInOutService;
import com.wangyang.stock.dao.IDao;
import com.wangyang.stock.po.InOut;
import com.wangyang.stock.vo.InOutVo;

public class InOutServiceImp implements IInOutService {

	private IDao dao;

	public IDao getDao() {
		return dao;
	}

	public void setDao(IDao dao) {
		this.dao = dao;
	}

	public boolean createInOut(InOutVo inOutVo) {
		// TODO Auto-generated method stub
		InOut inOut = new InOut();
		BeanUtils.copyProperties(inOutVo, inOut);
		return dao.create(inOut);
	}

	public boolean deleteInOut(InOutVo inOutVo) {
		// TODO Auto-generated method stub
		InOut inOut = new InOut();
		BeanUtils.copyProperties(inOutVo, inOut);
		return dao.delete(inOut);
	}

	public boolean updateInOut(InOutVo inOutVo) {
		// TODO Auto-generated method stub
		InOut inOut = new InOut();
		BeanUtils.copyProperties(inOutVo, inOut);
		return dao.update(inOut);
	}

	public List selectInOut(InOutVo inOutVo) {
		// TODO Auto-generated method stub

		StringBuffer hql = new StringBuffer("from InOut io where 1=1 ");
		if (null != inOutVo) {
			if (null != inOutVo.getInoutCompanyName()) {
				hql.append(" and io.inoutCompanyName like '%");
				hql.append(inOutVo.getInoutCompanyName());
				hql.append("%'");
			}
		}
		List list = dao.select(hql.toString());
		List volist = new ArrayList();
		for (int i = 0; i < list.size(); i++) {
			InOut io = (InOut)list.get(i);
			InOutVo ioVo = new InOutVo();
			BeanUtils.copyProperties(io, ioVo);
			volist.add(ioVo);
		}
		return volist;
	}

}
